$OpenBSD: patch-channels_chan_sip_c,v 1.24 2015/06/08 08:44:52 sthen Exp $

https://issues.asterisk.org/jira/secure/attachment/46850/fax-deadlock-v2.patch-11.3.0

--- channels/chan_sip.c.orig	Thu Jun  4 01:44:42 2015
+++ channels/chan_sip.c	Fri Jun  5 10:41:19 2015
@@ -8306,8 +8306,6 @@ static struct ast_frame *sip_read(struct ast_channel *
 			ast_channel_unlock(ast);
 			if (ast_exists_extension(ast, target_context, "fax", 1,
 				S_COR(ast_channel_caller(ast)->id.number.valid, ast_channel_caller(ast)->id.number.str, NULL))) {
-				ast_channel_lock(ast);
-				sip_pvt_lock(p);
 				ast_verb(2, "Redirecting '%s' to fax extension due to CNG detection\n", ast_channel_name(ast));
 				pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast_channel_exten(ast));
 				if (ast_async_goto(ast, target_context, "fax", 1)) {
@@ -8316,10 +8314,10 @@ static struct ast_frame *sip_read(struct ast_channel *
 				ast_frfree(fr);
 				fr = &ast_null_frame;
 			} else {
-				ast_channel_lock(ast);
-				sip_pvt_lock(p);
 				ast_log(LOG_NOTICE, "FAX CNG detected but no fax extension\n");
 			}
+			ast_channel_lock(ast);
+			sip_pvt_lock(p);
 		}
 	}
 
@@ -10632,6 +10630,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_r
 						ast_channel_unlock(p->owner);
 						if (ast_exists_extension(p->owner, target_context, "fax", 1,
 							S_COR(ast_channel_caller(p->owner)->id.number.valid, ast_channel_caller(p->owner)->id.number.str, NULL))) {
+							ast_log(LOG_WARNING, "Usage of 'faxdetect=[yes|t38]' setting in sip.conf is not recommended. Please consider Set(FAXOPT(faxdetect)=[yes|t38]) instead.\n");
 							ast_verb(2, "Redirecting '%s' to fax extension due to peer T.38 re-INVITE\n", ast_channel_name(p->owner));
 							pbx_builtin_setvar_helper(p->owner, "FAXEXTEN", ast_channel_exten(p->owner));
 							if (ast_async_goto(p->owner, target_context, "fax", 1)) {
